<?php
class Sosweb_Acl extends Zend_Acl
{
	public function __construct()
	{
		//create role
		$roleNologged = new Zend_Acl_Role(Sosweb_Const_CarrockConst::$USER_STATUS_NOLOGGED);
		$roleUser = new Zend_Acl_Role(Sosweb_Const_CarrockConst::$USER_STATUS_USER);
		$roleAdmin = new Zend_Acl_Role(Sosweb_Const_CarrockConst::$USER_STATUS_ADMIN);
		
		//create resource       
		$this->add(new Zend_Acl_Resource($this->createResource('index', 'index')));
		$this->add(new Zend_Acl_Resource($this->createResource('error', 'error')));
        $this->add(new Zend_Acl_Resource($this->createResource('auth', 'index')));
        $this->add(new Zend_Acl_Resource($this->createResource('auth', 'login')));
        $this->add(new Zend_Acl_Resource($this->createResource('auth', 'logout')));
        $this->add(new Zend_Acl_Resource($this->createResource('complaint', 'index')));
        $this->add(new Zend_Acl_Resource($this->createResource('complaint', 'add')));
        $this->add(new Zend_Acl_Resource($this->createResource('complaint', 'view')));
        $this->add(new Zend_Acl_Resource($this->createResource('complaint', 'details')));
        $this->add(new Zend_Acl_Resource($this->createResource('contact', 'index')));
        $this->add(new Zend_Acl_Resource($this->createResource('contracts', 'index')));
        $this->add(new Zend_Acl_Resource($this->createResource('contracts', 'add')));
        $this->add(new Zend_Acl_Resource($this->createResource('contracts', 'view')));
        $this->add(new Zend_Acl_Resource($this->createResource('contracts', 'archive')));
        $this->add(new Zend_Acl_Resource($this->createResource('contracts', 'details')));
        $this->add(new Zend_Acl_Resource($this->createResource('contracts', 'delete')));
        $this->add(new Zend_Acl_Resource($this->createResource('contracts', 'correction')));
        $this->add(new Zend_Acl_Resource($this->createResource('contracts', 'apply')));
        $this->add(new Zend_Acl_Resource($this->createResource('faq', 'index')));
        $this->add(new Zend_Acl_Resource($this->createResource('offer', 'index')));
        $this->add(new Zend_Acl_Resource($this->createResource('pack', 'index')));
        $this->add(new Zend_Acl_Resource($this->createResource('prices', 'index')));
        $this->add(new Zend_Acl_Resource($this->createResource('regulation', 'index')));
        $this->add(new Zend_Acl_Resource($this->createResource('user', 'index')));
        $this->add(new Zend_Acl_Resource($this->createResource('user', 'profile')));
        $this->add(new Zend_Acl_Resource($this->createResource('user', 'editProfile')));
        $this->add(new Zend_Acl_Resource($this->createResource('user', 'add')));
        $this->add(new Zend_Acl_Resource($this->createResource('user', 'view')));
        $this->add(new Zend_Acl_Resource($this->createResource('user', 'delete')));
        $this->add(new Zend_Acl_Resource($this->createResource('user', 'edit')));
        $this->add(new Zend_Acl_Resource($this->createResource('user', 'remind')));
        $this->add(new Zend_Acl_Resource($this->createResource('message', 'index')));
                                                
		//setup roles
		$this->addRole($roleNologged); 
        $this->addRole($roleUser, $roleNologged);
        $this->addRole($roleAdmin, $roleUser);

        //setup access list
        $this->allow($roleNologged, $this->createResource('index', 'index'));
        $this->allow($roleNologged, $this->createResource('error', 'error'));
        $this->allow($roleNologged, $this->createResource('auth', 'index'));
        $this->allow($roleNologged, $this->createResource('auth', 'login'));
        $this->allow($roleNologged, $this->createResource('contact', 'index'));
        $this->allow($roleNologged, $this->createResource('offer', 'index'));
        $this->allow($roleNologged, $this->createResource('pack', 'index'));
        $this->allow($roleNologged, $this->createResource('prices', 'index'));
		$this->allow($roleNologged, $this->createResource('regulation', 'index'));
		$this->allow($roleNologged, $this->createResource('user', 'add'));
		$this->allow($roleNologged, $this->createResource('user', 'remind'));
		$this->allow($roleNologged, $this->createResource('message', 'index'));
		
		$this->allow($roleUser, $this->createResource('auth', 'logout'));
		$this->allow($roleUser, $this->createResource('faq', 'index'));
		$this->allow($roleUser, $this->createResource('contracts', 'index'));
		$this->allow($roleUser, $this->createResource('contracts', 'add'));
		$this->allow($roleUser, $this->createResource('contracts', 'archive'));
		$this->allow($roleUser, $this->createResource('contracts', 'details'));
		$this->allow($roleUser, $this->createResource('user', 'profile'));
		$this->allow($roleUser, $this->createResource('user', 'editProfile'));

		$this->allow($roleAdmin, $this->createResource('complaint', 'index'));
		$this->allow($roleAdmin, $this->createResource('complaint', 'add'));
		$this->allow($roleAdmin, $this->createResource('complaint', 'view'));
		$this->allow($roleAdmin, $this->createResource('complaint', 'details'));
		$this->allow($roleAdmin, $this->createResource('contracts', 'delete'));
		$this->allow($roleAdmin, $this->createResource('contracts', 'view'));
		$this->allow($roleAdmin, $this->createResource('contracts', 'correction'));
		$this->allow($roleAdmin, $this->createResource('contracts', 'apply'));
		$this->allow($roleAdmin, $this->createResource('user', 'index'));
		$this->allow($roleAdmin, $this->createResource('user', 'view'));	
		$this->allow($roleAdmin, $this->createResource('user', 'delete'));	
		$this->allow($roleAdmin, $this->createResource('user', 'edit'));	
	}

	public function createResource($controller, $action)
	{
		return (($controller != null ? $controller : '/index').($action != null ? $action : '/index'));
	}
}